package com.omt.tarjimdinek.domain.translate.entity;


import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.log4j.Logger;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.member.entity.Langue;
import com.omt.tarjimdinek.domain.member.entity.Membre;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * translation request
 * @author chabane
 *
 */
@Entity
@Table(name="a01_dmdtrd")
public class DemandeTraduction  implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(DemandeTraduction.class);
    
	/** ID SGBD */
	@Column(name="CNDMDTRD", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
	@Version
	private Integer version;
	 
	/** source language */
	@NotNull
	@JoinColumn(name="CNLNG1", nullable=false)
	@ManyToOne
	private Langue langueSource;
	
	/** target language */
	@NotNull
	@JoinColumn(name="CNLNG2", nullable=false)
	@ManyToOne
	private Langue langeCible;
	
	/** detail of video */
	@NotNull
	@JoinColumn(name="CNDTLVDO", nullable=false)
	@ManyToOne
	private DetailVideo detailVideo;
	
	@OneToMany(mappedBy="demandeTraduction", fetch=FetchType.LAZY)
	private List<LigneOriginale> listeLignesOriginales;
	
	/**  */
	@NotNull
	@JoinColumn(name = "CNMBR", nullable = false)
	@ManyToOne
	private Membre demandeur;
	
	/** define if a request is accepted */
	@NotNull
	@Column(name="BOACC", nullable=false, length=45)
	private Boolean accepte;

	/** state of request */
	@NotNull
	@JoinColumn(name = "CNETDMD", nullable = false)
	@ManyToOne
	private EtatDemande etatDemande;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Langue getLangueSource() {
		return langueSource;
	}

	public void setLangueSource(Langue langueSource) {
		this.langueSource = langueSource;
	}

	public Langue getLangeCible() {
		return langeCible;
	}

	public void setLangeCible(Langue langeCible) {
		this.langeCible = langeCible;
	}

	public DetailVideo getDetailVideo() {
		return detailVideo;
	}

	public void setDetailVideo(DetailVideo detailVideo) {
		this.detailVideo = detailVideo;
	}

	public List<LigneOriginale> getListeLignesOriginales() {
		return listeLignesOriginales;
	}

	public void setListeLignesOriginales(List<LigneOriginale> listeLignesOriginales) {
		this.listeLignesOriginales = listeLignesOriginales;
	}

	public Membre getDemandeur() {
		return demandeur;
	}

	public void setDemandeur(Membre demandeur) {
		this.demandeur = demandeur;
	}

	public Boolean getAccepte() {
		return accepte;
	}

	public void setAccepte(Boolean accepte) {
		this.accepte = accepte;
	}

	public EtatDemande getEtatDemande() {
		return etatDemande;
	}

	public void setEtatDemande(EtatDemande etatDemande) {
		this.etatDemande = etatDemande;
	}

	@Transient
	public boolean isIdSet() {
		return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getId());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("accepte", getAccepte()) //
                .add("demandeur", getDemandeur()) //
                .add("detailVideo", getDetailVideo()) //
                .add("etatDemande", getEtatDemande()) //
                .add("langueSource", getLangueSource()) //
                .add("langueCible", getLangeCible()) //
                .add("listeLignesOriginales",getListeLignesOriginales()) //
                .add("version", getVersion()) //
                .toString();
    }
}
